/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-06-02
 * Time: 8:53
 */
class Solution2 {
    long prev = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if(root == null) {
            return true;
        }
        boolean left = isValidBST(root.left);
        //剪枝
        if(left == false) {
            return false;
        }
        boolean cur = false;
        if(root.val > prev) {
            cur = true;
        }
        prev = root.val;
        //剪枝
        boolean right = isValidBST(root.right);
        if(right == false) {
            return false;
        }
        return left && cur && right;

    }
}
